//
//  AvchatKit.h
//  DCAvchatKit
//
//  Created by zhangtao on 2020/9/16.
//  Copyright © 2020年 zhangtao. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <DCMessageKit/DCMessageKit.h>
#import <DCUtilKit/DCUtilKit.h>
#import "DCAvchatCallInvitationDelegate.h"
#import "DCAvchatCalleeStateDelegate.h"
#import "DCAvchatCallStateDelegate.h"
#import "DCAvchatKitMacro.h"
#import "DCAvchatCallControlDelegate.h"
#import "DCAvchatAdapter.h"

NS_ASSUME_NONNULL_BEGIN

@interface AvchatKit : NSObject<DCAvchatCallStateDelegate,DCAvchatCallControlDelegate,DCCustomMessageDelegate,DCAvchatSendScreenDelegate,GCDAsyncSocketDelegate>

+ (instancetype) sharedKit;

//消息适配器
@property(nonatomic,strong) DCAvchatAdapter *avchatAdapter;

#pragma mark 存储数据

//配置信息
@property(nonatomic,strong) NSMutableDictionary *configInfo;
//后台服务地址
@property(nonatomic,copy) NSString *serviceUrl;
//登录信息
@property(nonatomic,strong) NSMutableDictionary *loginInfo;
//呼叫信息
@property(nonatomic,strong) NSDictionary *callInfo;

#pragma mark 委托

//呼叫邀请委托
@property(nonatomic,weak) id<DCAvchatCallInvitationDelegate> avchatCallInvitationDelegate;
//对方取消/拒绝/繁忙委托
@property(nonatomic,weak) id<DCAvchatCalleeStateDelegate> avchatCalleeStateDelegate;
//通话信息委托
@property(nonatomic,weak) id<DCAvchatCallStateDelegate> avchatCallStateDelegate;
//通话控制信息委托
@property(nonatomic,weak) id<DCAvchatCallControlDelegate> avchatCallControlDelegate;
//投屏委托
@property(nonatomic,weak) id<DCAvchatSendScreenDelegate> avchatSendScreenDelegate;

#pragma mark 回调

//呼叫坐席-回调
@property(nonatomic,strong) void(^ __nullable callBlock)(DCError * __nullable error,NSDictionary * __nullable data);

#pragma mark 属性变量

//本地视频图像
@property(nonatomic,strong) UIView *localView;
//呼叫坐席-成功后等待接收消息结果计时器
@property(nonatomic,strong) NSTimer * __nullable callInTimer;
//呼叫坐席-发送通话邀请结果计时器
@property(nonatomic,strong) NSTimer * __nullable callInInviteTimer;
//呼叫超时
@property(nonatomic,strong) NSTimer * __nullable callTimer;
//接通超时
@property(nonatomic,strong) NSTimer * __nullable connectTimer;
//呼叫坐席-返回结果标记
@property(nonatomic,assign) BOOL callInResultFlag;
//呼叫坐席-返回结果超时标记
@property(nonatomic,assign) BOOL callInTimeoutFlag;
//呼叫坐席-发送通话邀请结果标记
@property(nonatomic,assign) BOOL callInInviteResultFlag;
//呼叫坐席-发送通话邀请超时应答标记
@property(nonatomic,assign) BOOL callInInviteTimeoutFlag;
//最后加入的房间Id
@property(nonatomic,copy) NSString *lastJoinRoomId;
//最后加入的房间callid
@property(nonatomic,assign) UInt64 lastJoinRoomCallId;
//最后通话的agentId
@property(nonatomic,copy) NSString *lastAgentId;
//呼叫邀请信息
@property(nonatomic,strong) NSDictionary *callInviteInfo;
//呼叫时调用接口返回的信息
@property(nonatomic,strong) NSDictionary *callInResponseInfo;
//呼叫时生成的sessionJournalId
@property(nonatomic,copy) NSString *callInSessionJournalId;
//通话中又有新的通话邀请的账号
@property(nonatomic,copy) NSString *busyingInvitedAccount;
//投屏状态
@property(nonatomic,assign) BOOL sendScreenFlag;
//摄像头方向
@property(nonatomic,assign) DCAvchatNetCallCamera avchatNetCallCamera;
//是否静音
@property(nonatomic,assign) BOOL avchatNetCallIsMute;
//是否打开麦克风
@property(nonatomic,assign) BOOL avchatNetCallSpeakerStatus;
//是否暂停通话状态
@property(nonatomic,assign) BOOL avchatNetCallIsPauseStatus;
//网络探测id
@property(nonatomic,assign) UInt64 avchatNetCallDetectTaskId;
//呼叫/被叫标志
@property(nonatomic,assign) DCAvchatCallFlag avchatNetCallFlag;
//群组id
@property(nonatomic,strong) NSString *lastTeamId;
//通话中的用户
@property(nonatomic,strong) NSMutableArray *joinedUsers;
//通话中的用户备份
@property(nonatomic,strong) NSMutableArray *joinedUsersBak;
//消息类
@property(nonatomic,strong) MessageKit *messageKit;

//投屏
@property(nonatomic,strong) GCDAsyncSocket *socket;
@property(nonatomic,strong) dispatch_queue_t queue;
@property(nonatomic,strong) NSMutableArray *sockets;
@property(nonatomic,assign) NTESTPCircularBuffer *recvBuffer;

@property(nonatomic,strong) NSString *hangupType;

#pragma mark 外部提供的方法
 
- (void) initWithServiceUrl:(NSString* __nullable)url;

- (void) login:(NSDictionary*)loginInfo callback:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) logout;

- (void) call:(NSDictionary*)callInfo callback:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) answer:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) refuse:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) hangUp:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) addCallInvitationDelegate:(id<DCAvchatCallInvitationDelegate>)delegate;

- (void) removeCallInvitationDelegate;

- (void) cancel:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) addCalleeStateDelegate:(id<DCAvchatCalleeStateDelegate>)delegate;

- (void) removeCalleeStateDelegate;

- (void) addCallStateDelegate:(id<DCAvchatCallStateDelegate>)delegate;

- (void) removeCallStateDelegate;

- (void) switchAVControl:(DCAvchatNetCallMediaType)type;

- (void) addCallControlDelegate:(id<DCAvchatCallControlDelegate>)delegate;

- (void) removeCallControlDelegate;

- (void) addSendScreenDelegate:(id<DCAvchatSendScreenDelegate>)delegate;

- (void) removeSendScreenDelegate;

- (void) sendScreen;

- (void) cancelSendScreen;

- (BOOL) isSendScreen;

- (void) agreeSendScreen;

- (void) refuseSendScreen;

- (void) switchCamera;

- (void) toggleCamera:(BOOL)status;

- (BOOL) cameraStatus;

- (void) toggleMute:(BOOL)isMute;

- (BOOL) isMute;

- (void) toggleSpeaker:(BOOL)useSpeaker;

- (BOOL) isSpeaker;

- (void) togglePauseSession:(BOOL)isPause;

- (BOOL) isPauseSession;

- (void) detectNetwork:(int)type callback:(nullable void (^)(DCError *error,NSDictionary *data))callback;

- (void) stopDetectTask:(int)taskId;

- (void) takeSnapshot:(void(^)(UIImage * __nullable image))callback;

@end

NS_ASSUME_NONNULL_END
